package com.itzhoun.config;

import com.itzhoun.service.ZnStartDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhounan
 * @date 2024/01/25 21:55
 * @Description
 */
@Configuration
@EnableConfigurationProperties(value = {ZnStarterProperties.class})
@ConditionalOnClass
public class ZnStartAutoConfiguration {

    private final ZnStarterProperties znStarterProperties;

    @Autowired
    public ZnStartAutoConfiguration(ZnStarterProperties starterProperties) {
        this.znStarterProperties = starterProperties;
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "com.itzhoun", value = "enabled", havingValue = "true")
    public ZnStartDemoService znStartDemoService(){
        return new ZnStartDemoService(znStarterProperties.getPrefix(), znStarterProperties.getSuffix());
    }
}
